import {Component, Inject, OnInit} from '@angular/core';

let uniqueId = 0;

export class CompDataService {

  private readonly uniqueId
  constructor() {
    this.uniqueId = uniqueId + 1;
    uniqueId = uniqueId + 1
  }

  get id() {
    return this.uniqueId
  }
}

@Component({
  selector: 'app-comp-di',
  template: `
    <p>
      comp-di works!
    </p>
    <app-comp-di-child></app-comp-di-child>
  `,
  styles: [
    `
      :host {
        background: #ccc;
      }
    `
  ],
  providers: [
    {
      provide: CompDataService,
      useClass: CompDataService
    }
  ]
})
export class CompDiComponent implements OnInit {

  constructor(
     private diSvc: CompDataService
  ) { }

  ngOnInit(): void {
    console.log(this.diSvc.id);
  }

}
